import auctionhaus.Customer
import auctionhaus.Listing
import auctionhaus.Bid

class BootStrap {

    def init = { servletContext ->
        if (!Customer.count()) {
            def todd = new Customer(emailAddress: 'todd.becicka@gmail.com', password: 'todd1234', isAdmin: true).save(failOnError: true)
            def jeff = new Customer(emailAddress: 'jeff.lemmerman@gmail.com', password: 'jeff1234').save(failOnError: true)
            def mikecalvo = new Customer(emailAddress: 'mike@citronellasoftware.com', password: 'mike1234', isAdmin: true).save(failOnError: true)
            def mikehugo = new Customer(emailAddress: 'mike@piragua.com', password: 'mike1234', isAdmin: true).save(failOnError: true)
            def vb = new Listing(name: 'volleyball', endDateTime: new Date() + 5, seller: jeff, startingBidAmount: 20).save(failOnError: true)
            def laptop = new Listing(name: 'laptop', endDateTime: new Date() + 1, seller: jeff, startingBidAmount: 600).save(failOnError: true)
            def book = new Listing(name: 'textbook', endDateTime: new Date() + 1, seller: jeff, startingBidAmount: 50).save(failOnError: true)
            def bball = new Listing(name: 'basketball', endDateTime: new Date() + 5, seller: todd, startingBidAmount: 25).save(failOnError: true)
            def truck = new Listing(name: 'truck', endDateTime: new Date() + 5, seller: todd, startingBidAmount: 19000).save(failOnError: true)
            def snowboard = new Listing(name: 'snowboard', endDateTime: new Date() - 5, seller: todd, startingBidAmount: 200, isClosed: true ).save(validate: false)
            def bid = new Bid(bidder: todd, listing: snowboard, amount: 23)
            vb.addToBids(bid)
            vb.save(failOnError: true, flush: true)
            bid = new Bid(bidder: jeff, listing: vb , amount: 25)
            vb.addToBids(bid)
            vb.save(failOnError: true, flush: true)
        }
    }
    def destroy = {
    }
}
